<script>
import ImageUploader from "./ImageUploader.vue";

export default {
  name: 'WorkExperienceEditor',
  components: {ImageUploader},
  props: {
    modelValue: {
      type: Array,
      default: () => []
    }
  },
  data() {
    return {}
  },
  computed: {
    localValue: {
      get() {
        return this.modelValue
      },
      set(value) {
        this.updateValue(value)
      }
    }
  },
  methods: {
    updateValue(val) {
      this.$emit('update:modelValue', val)
    },
    insert(val) {
      const nv = this.modelValue
      nv.push(val)
      this.updateValue(nv)
    },
    remove(idx) {
      const nv = this.modelValue
      nv.splice(idx, 1)
      this.updateValue(nv)
    },
    addWork() {
      this.insert({})
    }
  }
}
</script>

<template>
  <div class="grid grid-cols-3">
    <div v-for="(work, idx) in localValue" :key="idx" class="m-2">
      <div class="border p-5 bg-gray-100 rounded-md">
        <div class="">
          <el-form-item label-position="top" label="公司名称">
            <el-input v-model="work.name" size="large"/>
          </el-form-item>
          <div class="grid-rows-2">
            <div>
              <el-text>Logo</el-text>
            </div>
            <image-uploader v-model="work.logo" />
          </div>
          <el-form-item label-position="top" label="入职-离职">
            <el-date-picker  range-separator="到" size="large" type="monthrange" v-model="work.timespan"/>
          </el-form-item>
          <el-form-item label-position="top" label="单位职位">
            <el-input v-model="work.position" size="large"/>
          </el-form-item>
          <el-form-item label="职测描述" label-position="top">
            <el-input type="textarea"  v-model="work.description" size="large" show-word-limit max="200"/>
          </el-form-item>
          <div class="flex justify-center">
            <el-button @click="remove(idx)" circle text icon="Delete"></el-button>
          </div>
        </div>
      </div>
    </div>
    <div class="flex justify-center mt-2">
      <el-button icon="Plus" circle @click="addWork"/>
    </div>
  </div>
</template>

<style scoped>

</style>